const db = require("../dbUtil/index");
const sql = require("../dbUtil/sql");

module.exports = {
    //歌曲评论
    songComment: (req, res) => {
        let {songsID} = req.query;
        db.query(sql.comments.song, [songsID], (err, results) => {
            if (err) {
                //返回一个json对象：状态码、状态描述、数据
                res.send({
                    code: 505,
                    msg: "数据库执行错误！",
                    data: {}
                });
            } else {
                //获取数据库数据
                res.send({
                    code: 200,
                    msg: "数据库执行成功！",
                    data: { song: results }
                });
            }
        })
    },
    //歌单评论
    songListComment: (req, res) => {
        let {songList_name} = req.query
        db.query(sql.comments.songListName, [songList_name], (err, results) => {
            if (err) {
                //返回一个json对象：状态码、状态描述、数据
                res.send({
                    code: 505,
                    msg: "数据库执行错误！",
                    data: {}
                });
            } else {
                //获取数据库数据
                res.send({
                    code: 200,
                    msg: "数据库执行成功！",
                    data: { songList: results }
                });
            }
        })
    },
    //歌曲写评论
    songWrite: (req, res) => {
        let { comment_uid, word, time, song_sid } = req.query;
        db.query(sql.comments.songWrite, [comment_uid, word, time, song_sid], (err, results) => {
            if (err) {
                //返回一个json对象：状态码、状态描述、数据
                res.send({
                    code: 505,
                    msg: "数据库执行错误！",
                    data: {}
                });
            } else {
                //获取数据库数据
                res.send({
                    code: 200,
                    msg: "评论成功！",
                    data: {}
                });
            }
        })
    },
    //歌单写评论
    songListWrite: (req, res) => {
        let { comment_uid, word, time, songList_name } = req.query;
        db.query(sql.comments.songListWrite, [comment_uid, word, time, songList_name], (err, results) => {
            if (err) {
                //返回一个json对象：状态码、状态描述、数据
                res.send({
                    code: 505,
                    msg: "数据库执行错误！",
                    data: {}
                });
            } else {
                //获取数据库数据
                res.send({
                    code: 200,
                    msg: "评论成功！",
                    data: {}
                });
            }
        })
    },
    //歌曲删评论
    songDelete: (req, res) => {
        let { comment_uid, word, time, song_sid } = req.query;
        db.query(sql.comments.songDelete, [comment_uid, word, time, song_sid], (err, results) => {
            if (err) {
                //返回一个json对象：状态码、状态描述、数据
                res.send({
                    code: 505,
                    msg: "数据库执行错误！",
                    data: {}
                });
            } else {
                //获取数据库数据
                res.send({
                    code: 200,
                    msg: "删除评论成功！",
                    data: {}
                });
            }
        })
    },
    //歌单删评论
    songListDelete: (req, res) => {
        let { comment_uid, word, time, songList_name } = req.query;
        db.query(sql.comments.songListDelete, [comment_uid, word, time, songList_name], (err, results) => {
            if (err) {
                //返回一个json对象：状态码、状态描述、数据
                res.send({
                    code: 505,
                    msg: "数据库执行错误！",
                    data: {}
                });
            } else {
                //获取数据库数据
                res.send({
                    code: 200,
                    msg: "删除评论成功！",
                    data: {}
                });
            }
        })
    },
}